package com.twu.biblioteca;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created with IntelliJ IDEA.
 * User: ruchita
 * Date: 18/9/13
 * Time: 4:40 PM
 * To change this template use File | Settings | File Templates.
 */
public class WelcomePage {
    public JPanel panel1;
    public JButton checkMemebershipDetailsButton;
    public JButton reserveABookButton;
    public JButton listTheBooksButton;
    private JButton movieInfoButton;
    private JPanel cardLayoutArea;
    private JButton logInButton;
    public String LoginStatus;


    public WelcomePage(final String userLibraryNumber, final  JFrame welcomeFrame) {
        //reserBook option is available for only loge inned users
        if (userLibraryNumber.equals("")) {
            reserveABookButton.setVisible(false);
        } else {
            logInButton.setVisible(false);          //Login option is not available for users who are log inned
            //Get username from databse using UserLibraryNumber
            ValidateUser v = new ValidateUser();
            cardLayoutArea.add("Welcome text", new JLabel("welcome " + v.getName(userLibraryNumber) + " !!!Enjoy the library"));
        }
        reserveABookButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                JFrame frame = new JFrame("ReserveBookFromList");
                frame.setContentPane(new ReserveBookFromList().panel1);
                setFrameAttributes(frame);
            }
        });
        listTheBooksButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                JFrame frame = new JFrame("ListBooksPage");
                frame.setContentPane(new ListBooksPage().panel1);
                setFrameAttributes(frame);
            }
        });
        checkMemebershipDetailsButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                if (!userLibraryNumber.equals("")) {
                    JFrame frame = new JFrame("UserDetailsPage");
                    frame.setContentPane(new UserDetailsPage(userLibraryNumber).panel1);
                    setFrameAttributes(frame);
                } else
                    JOptionPane.showMessageDialog(panel1, "Please Talk to Librarian.Thank You");
            }
        });
        movieInfoButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                JFrame frame = new JFrame("MovieInfoPage");
                frame.setContentPane(new MovieInfoPage().panel1);
                setFrameAttributes(frame);

            }
        });
        logInButton.addActionListener(new ActionListener() {
            @Override

            public void actionPerformed(ActionEvent actionEvent) {
                welcomeFrame.dispose();
                JFrame frame = new JFrame("LoginPage");
                frame.setContentPane(new LoginPage(frame).panel1);
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.pack();
                frame.setSize(300,150);
                frame.setVisible(true);
            }
        });
    }

    private void setFrameAttributes(JFrame frame) {
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setSize(300, 300);
        frame.setVisible(true);
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        panel1 = new JPanel();
        panel1.setLayout(new BorderLayout(0, 0));
        panel1.setBackground(new Color(-1));
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel2, BorderLayout.NORTH);
        final JPanel panel3 = new JPanel();
        panel3.setLayout(new BorderLayout(0, 0));
        panel3.setBackground(new Color(-1));
        panel2.add(panel3, new com.intellij.uiDesigner.core.GridConstraints(0, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        logInButton = new JButton();
        logInButton.setText("Log In");
        panel3.add(logInButton, BorderLayout.EAST);
        final JToolBar toolBar1 = new JToolBar();
        toolBar1.setBackground(new Color(-13408513));
        panel2.add(toolBar1, new com.intellij.uiDesigner.core.GridConstraints(1, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 20), null, 0, false));
        checkMemebershipDetailsButton = new JButton();
        checkMemebershipDetailsButton.setBackground(new Color(-13408513));
        checkMemebershipDetailsButton.setText("Check Memebership Details");
        toolBar1.add(checkMemebershipDetailsButton);
        reserveABookButton = new JButton();
        reserveABookButton.setBackground(new Color(-13421569));
        reserveABookButton.setEnabled(true);
        reserveABookButton.setText("Reserve a book");
        toolBar1.add(reserveABookButton);
        listTheBooksButton = new JButton();
        listTheBooksButton.setBackground(new Color(-13408513));
        listTheBooksButton.setText("List the books");
        toolBar1.add(listTheBooksButton);
        movieInfoButton = new JButton();
        movieInfoButton.setBackground(new Color(-13408513));
        movieInfoButton.setText("Movie Info");
        toolBar1.add(movieInfoButton);
        cardLayoutArea = new JPanel();
        cardLayoutArea.setLayout(new CardLayout(0, 0));
        cardLayoutArea.setBackground(new Color(-1));
        panel1.add(cardLayoutArea, BorderLayout.CENTER);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return panel1;
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */

}
